//
//  AyAccountTool.m
//  xWeibo
//
//  Created by alvis mac on 8/6/15.
//  Copyright (c) 2015 alvis. All rights reserved.
//

#import "AyAccountTool.h"
#define IWAccountFile [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"account.data"]

@implementation AyAccountTool

+ (void)saveAccount:(AyAccount *)account{
    NSDate *now=[NSDate date];
    account.expiresTime=[now dateByAddingTimeInterval:account.expires_in];
    [NSKeyedArchiver archiveRootObject:account toFile:IWAccountFile];
}


+ (AyAccount *)account{
    AyAccount *account=[NSKeyedUnarchiver unarchiveObjectWithFile:IWAccountFile];
    NSDate *now=[NSDate date];
    if([now compare:account.expiresTime]==NSOrderedAscending){
        return account;
    }else{
        return nil;
    }
}


@end
